package com.jun.admin.core.model;


import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.context.AnalysisContext;
import com.jun.admin.core.model.excel.anno.ExcelRequiredValid;
import com.jun.admin.core.model.excel.converts.YesOrNoConverter;
import com.jun.admin.core.model.excel.entity.ExcelBaseEntity;
import com.jun.admin.core.utils.ExcelValidUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
* @author yuejun.li
* @since 2024-06-13
*/
@Data
@Table(name = "jun_student")
@ApiModel(value = "JunStudent对象", description = "")
@ExcelIgnoreUnannotated
@ColumnWidth(25)
public class JunStudent implements ExcelBaseEntity,Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("主键")
    @Id
    private Integer id;

    @ApiModelProperty("学生名称")
    @Column(name = "student_name")
    @ExcelProperty(index = 0,value = "学生名称")
    @ExcelRequiredValid
    private String studentName;

    @ApiModelProperty("年龄")
    @Column(name = "age")
    @ExcelProperty(index = 1,value = "年龄")
    private Integer age;

    @ApiModelProperty("出生日期")
    @Column(name = "birthday")
    @DateTimeFormat("yyyy年MM月dd日 HH时mm分ss秒")
    @ExcelProperty(index = 2,value = "出生日期")
    private LocalDateTime birthday;

    @ApiModelProperty("是否活跃")
    @Column(name = "is_active")
    @ExcelProperty(index = 3,value = "是否活跃",converter = YesOrNoConverter.class)
    private Integer isActive;

    public static final String ID = "id";

    public static final String STUDENT_NAME = "studentName";

    public static final String AGE = "age";

    /**
     * 校验逻辑
     * @return
     */
    @Override
    public boolean check(AnalysisContext context) {
        return ExcelValidUtil.valid(this,context);
    }
}
